package ClientProxy;

import java.io.File;
import java.rmi.RMISecurityManager;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class Main {
	public static void main(String[] args) {
		try {
			System.out.println("[PROXY] Loading..");

	        //System.setProperty("javax.net.ssl.trustStore", new File("Policies/ClientProxyTrustStore").getCanonicalPath());
	        //System.setProperty("javax.net.ssl.keyStore", new File("Policies/ClientProxyKeyStore").getCanonicalPath());
	        //System.setProperty("javax.net.ssl.keyStorePassword", "nieldeckx");
	        //System.setProperty("java.security.policy", new File("Policies/clientproxy.policy").getCanonicalPath());
	        
			if(System.getSecurityManager() == null) {
				System.setSecurityManager(new RMISecurityManager());
			}
			
	        String address = "localhost";
	        int port = 1099;
	        
	        if (args.length > 0)
	        	address = args[0];
	        if (args.length > 1)
	        	port =  Integer.valueOf(args[1]);
			
			Registry registry = LocateRegistry.getRegistry(address, port);
			Registry registryImplementation = (Registry)registry.lookup("RegistryImplementation");
			ProxyImplementation proxyImplementation = new ProxyImplementation(registryImplementation);
			registryImplementation.rebind("ClientProxy", proxyImplementation);
			
			System.out.println("[PROXY] Loaded, proxy can be used now.");

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
